﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; 
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class deleteEntry : System.Web.UI.Page
{
    private int delCompId=0; 
    
    protected void Page_Load(object sender, EventArgs e)
    {
        Label2.Text = "Logged in as: " + Context.User.Identity.Name;
        
        logoutButton.Visible = true;
        logoutButton.Text = "[Logout]";

        delCompId = Convert.ToInt32(Request.Params["CompId"]);

        if (delCompId == 0)
        {
            Response.Redirect("Default.aspx");
        }
    
        Literal1.Text = load_data(delCompId).ToString();  
    }

    public StringBuilder load_data(int comp_id)
    {
        cmpEntry delCmp = new cmpEntry();
        delCmp.cmpGet(delCompId);

        StringBuilder sb = new StringBuilder(); 
        
        sb.Append("<TABLE border=1>");
        
        sb.Append("<TR>");
        sb.Append("<TD>Company: </TD>");
        sb.Append("<TD>"+delCmp.cmpName +"</TD>");
        sb.Append("</TR>");

        sb.Append("<TR>");
        sb.Append("<TD>Country: </TD>");
        sb.Append("<TD>" + delCmp.cmpCountry + "</TD>");
        sb.Append("</TR>");

        sb.Append("<TR>");
        sb.Append("<TD>City: </TD>");
        sb.Append("<TD>" + delCmp.cmpCity + "</TD>");
        sb.Append("</TR>");

        sb.Append("<TR>");
        sb.Append("<TD>Address: </TD>");
        sb.Append("<TD>" + delCmp.cmpAddress + "</TD>");
        sb.Append("</TR>");

        sb.Append("<TR>");
        sb.Append("<TD>E-mail: </TD>");
        sb.Append("<TD>" + delCmp.cmpEmail + "</TD>");
        sb.Append("</TR>");

        sb.Append("<TR>");
        sb.Append("<TD>Phone: </TD>");
        sb.Append("<TD>" + delCmp.cmpPhone + "</TD>");
        sb.Append("</TR>");

        sb.Append("<TR>");
        sb.Append("<TD>Creator: </TD>");

        cmpUser ownername = new cmpUser(); 
        
        sb.Append("<TD>" + ownername.get_full_name(delCmp.cmpOwner) + "</TD>");
                
        sb.Append("</TR>");

        sb.Append("<TR>");
        sb.Append("<TD>Created: </TD>");
        sb.Append("<TD>" + delCmp.cmpCreatedDate + "</TD>");
        sb.Append("</TR>");

        sb.Append("</TABLE>");

        return sb; 
    }

    protected void btnDelete(object sender, EventArgs e)
    {
        cmpEntry delEntry = new cmpEntry();
        
        delEntry.cmpGet(delCompId);

        cmpUser check_user = new cmpUser();

        if (!(check_user.get_id(Context.User.Identity.Name) == delEntry.cmpOwner))
        {
            Response.Redirect("Default.aspx");
        }
        

        delEntry.app_path = Request.PhysicalApplicationPath;
      
        delEntry.cmpDelete();
        
        Response.Redirect("Default.aspx");
    }

    protected void btnCancel(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }

    protected void btnLogout_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Response.Redirect("Default.aspx");
    }
}